import re
import sys
import traceback
import urllib.error
import urllib.parse
import urllib.request

from proxy_generator import ProxyGenerator

class CndashproxyGenerator(ProxyGenerator):
  def __init__(self):
    super().__init__()
    self.pages = ['http://cn-proxy.com/', 'http://cn-proxy.com/archives/218']
    self._ip_port_pattern = re.compile(
        '<td>(\d*.\d*.\d*.\d*)</td>[^<]*<td>(\d+)</td>')
  
  def GetIps(self, webdata):
    webdata = webdata.decode('utf8')
    ip_ports = self._ip_port_pattern.findall(webdata)
    for pair in ip_ports:
      proxy = pair[0] + ':' + pair[1]
      yield proxy
